package com.zfdang.touchhelper.tool;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.WindowManager;

/**
 * @author Aivin
 * created on 2023/11/10
 * des:
 */
public class MyDeviceInforHelper {
    public static WindowManager myWindowManager;
    public static DisplayMetrics myDisplayMetrics;

    private static WindowManager myGetWindowManageger(Context context) {
        if (myWindowManager == null) {
            myWindowManager = (WindowManager) (context.getSystemService(Context.WINDOW_SERVICE));
        }
        return myWindowManager;
    }

    private static DisplayMetrics myGetDisplayMetrics() {
        if (myDisplayMetrics == null) {
            myDisplayMetrics = new DisplayMetrics();
        }
        return myDisplayMetrics;
    }


    public static int getHeight(Activity mActivity) {
        mActivity.getWindowManager().getDefaultDisplay().getMetrics(myGetDisplayMetrics());
        return myGetDisplayMetrics().heightPixels;

    }

    public static int dp2px(Context context, int dp) {
        return (int) TypedValue.applyDimension(1, (float) dp, context.getResources().getDisplayMetrics());
    }

    public static int getWindowHeigh(Context context) {
        myGetWindowManageger(context).getDefaultDisplay().getRealMetrics(myGetDisplayMetrics());
        return myGetDisplayMetrics().heightPixels;
    }

    public static int getWindowWidth(Context context) {
        myGetWindowManageger(context).getDefaultDisplay().getMetrics(myGetDisplayMetrics());
        return myGetDisplayMetrics().widthPixels;
    }

}
